<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Define Subst Example (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Define Subst Example (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Define Subst Example (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Define-Subst.html" rel="up" title="Define Subst">
<link href="Define-Subst-Pattern-Matching.html" rel="next" title="Define Subst Pattern Matching">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Define-Subst-Example">
<div class="nav-panel">
<p>
Next: <a href="Define-Subst-Pattern-Matching.html" accesskey="n" rel="next">Pattern Matching in <code class="code">define_subst</code></a>, Up: <a href="Define-Subst.html" accesskey="u" rel="up">RTL Templates Transformations</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="define_005fsubst-Example"><span>17.21.1 <code class="code">define_subst</code> Example<a class="copiable-link" href="#define_005fsubst-Example"> &para;</a></span></h4>
<a class="index-entry-id" id="index-define_005fsubst-1"></a>

<p>To illustrate how <code class="code">define_subst</code> works, let us examine a simple
template transformation.
</p>
<p>Suppose there are two kinds of instructions: one that touches flags and
the other that does not.  The instructions of the second type could be
generated with the following <code class="code">define_subst</code>:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_subst &quot;add_clobber_subst&quot;
  [(set (match_operand:SI 0 &quot;&quot; &quot;&quot;)
        (match_operand:SI 1 &quot;&quot; &quot;&quot;))]
  &quot;&quot;
  [(set (match_dup 0)
        (match_dup 1))
   (clobber (reg:CC FLAGS_REG))])
</pre></div>

<p>This <code class="code">define_subst</code> can be applied to any RTL pattern containing
<code class="code">set</code> of mode SI and generates a copy with clobber when it is
applied.
</p>
<p>Assume there is an RTL template for a <code class="code">max</code> instruction to be used
in <code class="code">define_subst</code> mentioned above:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_insn &quot;maxsi&quot;
  [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
        (max:SI
          (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
          (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  &quot;&quot;
  &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
 [...])
</pre></div>

<p>To mark the RTL template for <code class="code">define_subst</code> application,
subst-attributes are used.  They should be declared in advance:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_subst_attr &quot;add_clobber_name&quot; &quot;add_clobber_subst&quot; &quot;_noclobber&quot; &quot;_clobber&quot;)
</pre></div>

<p>Here &lsquo;<samp class="samp">add_clobber_name</samp>&rsquo; is the attribute name,
&lsquo;<samp class="samp">add_clobber_subst</samp>&rsquo; is the name of the corresponding
<code class="code">define_subst</code>, the third argument (&lsquo;<samp class="samp">_noclobber</samp>&rsquo;) is the
attribute value that would be substituted into the unchanged version of
the source RTL template, and the last argument (&lsquo;<samp class="samp">_clobber</samp>&rsquo;) is the
value that would be substituted into the second, transformed,
version of the RTL template.
</p>
<p>Once the subst-attribute has been defined, it should be used in RTL
templates which need to be processed by the <code class="code">define_subst</code>.  So,
the original RTL template should be changed:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_insn &quot;maxsi&lt;add_clobber_name&gt;&quot;
  [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
        (max:SI
          (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
          (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  &quot;&quot;
  &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
 [...])
</pre></div>

<p>The result of the <code class="code">define_subst</code> usage would look like the following:
</p>
<div class="example smallexample">
<pre class="example-preformatted">(define_insn &quot;maxsi_noclobber&quot;
  [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
        (max:SI
          (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
          (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))]
  &quot;&quot;
  &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
 [...])
(define_insn &quot;maxsi_clobber&quot;
  [(set (match_operand:SI 0 &quot;register_operand&quot; &quot;=r&quot;)
        (max:SI
          (match_operand:SI 1 &quot;register_operand&quot; &quot;r&quot;)
          (match_operand:SI 2 &quot;register_operand&quot; &quot;r&quot;)))
   (clobber (reg:CC FLAGS_REG))]
  &quot;&quot;
  &quot;max\t{%2, %1, %0|%0, %1, %2}&quot;
 [...])
</pre></div>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Define-Subst-Pattern-Matching.html">Pattern Matching in <code class="code">define_subst</code></a>, Up: <a href="Define-Subst.html">RTL Templates Transformations</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
